using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using Server;
using Server.Mobiles; 
using Server.Items;
using Server.Commands; 
using Server.Network;
using Server.Gumps;


namespace Server.Commands 
{
	public static class VendorCommand
	{
		public static void Initialize()
		{
			CommandSystem.Register( "Manager", AccessLevel.Administrator, new CommandEventHandler( Manager_OnCommand ) );
			CommandSystem.Register( "SaveStone", AccessLevel.Administrator, new CommandEventHandler( SaveStone_OnCommand ) );
		}

		[Usage( "Manager" )]
		[Description( "Spawning Vendor Manager." )]
		private static void Manager_OnCommand( CommandEventArgs e )
		{
			Mobile from = e.Mobile;
			VendorManager vm = new VendorManager( from );

			Timer.DelayCall( TimeSpan.Zero, new TimerStateCallback( SpawnManagerCallback ), new object[] { from, vm } );
		}

		private static void SpawnManagerCallback( object state )
		{
			object[] aState = (object[]) state;

			Mobile m = (Mobile) aState[0];
			Mobile spawn = (Mobile) aState[1];

			int x = SaveStone.StoneX;
			int y = SaveStone.StoneY;
			Map map = SaveStone.StoneMap;

			// to leave one and only one instance of savestone to save static array lists
			List<SaveStone> list = CommonTools.FindItemsOfType<SaveStone>();

			if ( !( list.Count > 0 ) )
			{
				SaveStone ss = new SaveStone();

				// Britain Bank of Felucca, next to Nerun's Championspawn Controller
				ss.MoveToWorld( new Point3D( x, y, map.GetAverageZ( x, y ) ), map );
			}

			spawn.MoveToWorld( m.Location, m.Map );
		}

		[Usage( "SaveStone" )]
		[Description( "Going to vendor mall Save Stone." )]
		private static void SaveStone_OnCommand( CommandEventArgs e )
		{
			Mobile from = e.Mobile;

			int x = SaveStone.StoneX + 1;
			int y = SaveStone.StoneY;
			Map map = SaveStone.StoneMap;

			BaseCreature.TeleportPets( from, new Point3D( x, y, map.GetAverageZ( x, y ) ), map );

			from.Combatant = null;
			from.Warmode = false;
			from.Hidden = true;

			from.PlaySound( 0x1FC );
			from.MoveToWorld( new Point3D( x, y, map.GetAverageZ( x, y ) ), map );
			from.PlaySound( 0x1FC );
		}
	}
}